<%@ page contentType="text/html;charset=UTF-8" language="java" %>



<%@ page import="com.summer.pojo.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<html>
<head>
    <meta charset="UTF-8"/>
    <title>图书后台管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/main.css"/>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/layer/layer.js"></script>
</head>
<body>
<%
    User user = (User) request.getSession().getAttribute("user");
%>
<div class="topbar-wrap white" >
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="index.html" class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="">首页</a></li>
                <li><a href="${pageContext.request.contextPath}/book/userfindAllBook" target="_blank">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="#"><%=user.getUsername()%></a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container clearfix" id="mainDiv">



<div class="admin_login_wrap" >
    <div class="adming_login_border">
        <div class="admin_input">
            <form  method="post" id="updataForm" action="#">
                <ul class="admin_items">
                    <li>
                        <label for="oldPassword"><span style="color: red">*</span>旧密码：</label>
                        <input type="password" name="oldPassword"  id="oldPassword" size="30" class="admin_input_style" />
                    </li>
                    <li>
                        <label for="newPassword1"><span style="color: red">*</span>新密码：</label>
                        <input type="password" name="newPassword1"  id="newPassword1" size="30" class="admin_input_style" />
                    </li>
                    <li>
                        <label for="newPassword2"><span style="color: red">*</span>确认新密码：</label>
                        <input type="password" name="newPassword2"  id="newPassword2" size="30" class="admin_input_style" />
                    </li>
                    <li>
                        <input type="button" id="btn" tabindex="3" value="修改密码" class="btn btn-primary" onclick="checkUpdate()"/>
                    </li>
                </ul>
            </form>
        </div>
    </div>
</div>
</div>
</body>
<script>
    function checkUpdate() {
        var oldPwd=$("#oldPassword").val();
        var newPwd1=$("#newPassword1").val();
        var newPwd2=$("#newPassword2").val();
        if (oldPwd=="" ||newPwd1==""||newPwd2==""){
            alert("所有密码均不能为空");
            return;
        }
        var Pwd="<%= user.getPassword()%>";
        var id="<%= user.getId()%>";
        var username="<%= user.getUsername()%>";
        var phone="<%= user.getPhone()%>";
        var address="<%= user.getAddress()%>";

        if (Pwd!==oldPwd){
            alert("旧密码输入错误")
            return;
        }
        if (newPwd1!==newPwd2){
            alert("新密码输入不一致!")
            return;
        }
        if(confirm("确认修改密码吗？")) {
            $.ajax({
                url: "/login/updateUser",
                type: "POST",
                contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                data: {
                    "id":id,
                    "username":username,
                    "phone":phone,
                    "address":address,
                    "password":newPwd2
                },
                success: function () {
                    alert("修改成功,返回登录页面!");
                    window.location = "/login";
                },
                error: function () {
                    alert("修改失败");
                    window.location = "/updateUserPS";
                }
            })
        }
    }
</script>
</html>